package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/nursingLevel")
@Api(tags = "护理等级接口")
public class NursingLevelController {
    @Autowired
    private NursingLevelService nursingLevelService;

    /**
     * 获取所有护理等级信息
     * @return
     */
    @GetMapping("/listAll")
    @ApiOperation("获取所有护理等级信息")
    public ResponseResult<List<NursingLevelVo>> all () {
        List<NursingLevelVo> nursingLevelVo = nursingLevelService.all();
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 添加护理等级信息
     * @return
     */
    @PostMapping("/insert")
    @ApiOperation( "添加护理等级信息")
    public ResponseResult add (@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.add(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 分页查询护理等级信息
     * @return
     */
    @GetMapping("/listByPage")
    @ApiOperation("分页查询护理等级信息")
    public ResponseResult getByPage (@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize,
                                     String name,
                                     Integer status) {
        PageResponse<NursingLevelVo> page = nursingLevelService.getByPage( pageNum, pageSize, name, status);
        return ResponseResult.success(page);
    }

    /**
     * 根据id查询护理等级信息
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation("根据id查询护理等级信息")
    public ResponseResult<NursingLevelVo> getById (@PathVariable Long id) {
        NursingLevelVo nursingLevelVo = nursingLevelService.getById(id);
        return ResponseResult.success(nursingLevelVo);
    }

    /**
     * 编辑更新护理等级信息
     * @return
     */
    @PutMapping("/update")
    @ApiOperation("编辑更新护理等级信息")
    public ResponseResult update (@RequestBody NursingLevelDto nursingLevelDto) {
        nursingLevelService.update(nursingLevelDto);
        return ResponseResult.success();
    }

    /**
     * 根据id删除护理等级信息
     * @param id
     * @return
     */
    @DeleteMapping("/delete/{id}")
    @ApiOperation("根据id删除护理等级信息")
    public ResponseResult deleteById (@PathVariable Long id) {
        nursingLevelService.deleteById(id);
        return ResponseResult.success();
    }

    /**
     * 启用/禁用护理等级信息
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用护理等级信息")
    public ResponseResult enableDisable (@PathVariable Long id, @PathVariable Integer status) {
        nursingLevelService.enableDisable(id, status);
        return ResponseResult.success();
    }
}
